package com.my.coolq.strategy;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.Validate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.google.common.collect.Maps;

/**
 * 接收消息处理策略支持者
 * @author ch
 *
 */
@Component
public class ReceiveMessagesHandleStrategySupport {
	
	/**
	 * 接收消息处理策略映射
	 */
	private Map<String, ReceiveMessagesHandleStrategy> strategyMaping = Maps.newHashMap();
	
	

	@Autowired
	public void setReceiveMessagesHandleStrategys(List<ReceiveMessagesHandleStrategy> receiveMessagesHandleStrategys) {
		Validate.notEmpty(receiveMessagesHandleStrategys, "receive messages handle strategy is empty");
		for (ReceiveMessagesHandleStrategy receiveMessagesHandleStrategy : receiveMessagesHandleStrategys) {
			strategyMaping.put(receiveMessagesHandleStrategy.getPostType(), receiveMessagesHandleStrategy);
		}
	}
	
	/**
	 * 获取接收消息处理策略
	 * @param postType 上报类型
	 * @return
	 */
	public ReceiveMessagesHandleStrategy getReceiveMessagesHandleStrategy(String postType){
		return strategyMaping.get(postType);
	}

}
